/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sputty.gui;


import java.awt.Component;
import javax.swing.ImageIcon;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import sputty.classes.ConnectionSettings;

/**
 *
 * @author mauro
 */
public class ConnectionTreeRendering extends DefaultTreeCellRenderer {
    ImageIcon RootIcon;
    ImageIcon Folder;
    ImageIcon FolderEmpty;
    ImageIcon Connection;
    
    public ConnectionTreeRendering(){
        RootIcon = new ImageIcon(this.getClass().getResource("/sputty/gui/resources/Root.png"));
        FolderEmpty = new ImageIcon(this.getClass().getResource("/sputty/gui/resources/Empty_folder.png"));
        this.Folder = new ImageIcon(this.getClass().getResource("/sputty/gui/resources/Open_folder.png"));
        this.Connection = new ImageIcon(this.getClass().getResource("/sputty/gui/resources/Connection.png"));
    }
    
    public Component getTreeCellRendererComponent(JTree tree, Object value,boolean sel,boolean expanded,boolean leaf, int row,boolean hasFocus){
        super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
        if(value.equals(tree.getModel().getRoot())){
            setIcon(RootIcon);
        }else{
            if(expanded){
                setIcon(Folder);
            }else{
                if(leaf){
                    if(((DefaultMutableTreeNode)value).getUserObject().toString().indexOf("ConnectionSettings") >= 0){
                        setIcon(Connection);
                        ConnectionSettings C = (ConnectionSettings)((DefaultMutableTreeNode)value).getUserObject();
                        setText(C.getName());
                        //setToolTipText(C.getHost() + "\n" + C.getUserName() + "\n" + C.getPassword());
                    }else{
                        setIcon(FolderEmpty);
                    }
                }else{
                    setIcon(FolderEmpty);
                }
            }
        }
        return this;        
    }
}
